package com.t.bricks.bussiness.service.stock.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.t.bricks.bussiness.db.dao.stock.StockDao;
import com.t.bricks.bussiness.service.stock.StockService;
import com.t.bricks.model.MsgEmity;

/**
 * 库存表'Stock表'基本业务操作类接口实现
 */
@Service
public class StockServiceImpl implements StockService {

	@Autowired
	private StockDao stockDao;

	/**
	 * 根据物品编号/仓库编号/批次取分组数据
	 * @param iWarehouse 启用仓库分组
	 * @param iBatch 启用批次分组
	 * @param sGoodsId 物品编号条件
	 * @param sWarehouseId 仓库编号条件
	 * @param sBatch 批次条件
	 * @return MsgEmity
	 */
	@Override
	public MsgEmity findByGroup(Integer iWarehouse, Integer iBatch, String sGoodsId,
			String sWarehouseId, String sBatch, Date dMakeDateSt, Date dMakeDateEd) {
		iWarehouse = null == iWarehouse || 1 != iWarehouse.intValue() ? 2 : 1;
		iBatch = null == iBatch || 1 != iBatch.intValue() ? 2 : 1;
		
		sGoodsId = null == sGoodsId ? null : sGoodsId.trim();
		sWarehouseId = null == sWarehouseId ? null : sWarehouseId.trim();
		sBatch = null == sBatch ? null : sBatch.trim();
		
		return stockDao.findByGroup(iWarehouse, iBatch, sGoodsId, sWarehouseId, sBatch, dMakeDateSt, dMakeDateEd);
	}
	
	/**
	 * 检查当前库存量
	 * @param sGoodsId 物品编号条件
	 * @param sWarehouseId 仓库编号条件
	 * @param sBatch 批次条件
	 * @return MsgEmity
	 */
	@Override
	public MsgEmity findQuantity(String sGoodsId, String sWarehouseId, String sBatch) {
		sGoodsId = null == sGoodsId ? null : sGoodsId.trim();
		sWarehouseId = null == sWarehouseId ? null : sWarehouseId.trim();
		sBatch = null == sBatch ? null : sBatch.trim();
		
		return stockDao.findQuantity(sGoodsId, sWarehouseId, sBatch);
	}

}
